local GuildWarFightTabPanel = app.mvc.createPanelClass(...)
local GuildWarFightGuildInfoRender = import("..renders.GuildWarFightGuildInfoRender")
local GuildWarFightTipPlateRender = import("..renders.GuildWarFightTipPlateRender")
local CrossServerGuildWarHelper = require("app.crossServer.views.guildWar.CrossServerGuildWarHelper")
--data =
function GuildWarFightTabPanel.createWithData(data, node)
    local sprite = GuildWarFightTabPanel.extend(node )
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end

function GuildWarFightTabPanel.create(node)
    return GuildWarFightTabPanel.createWithData(nil, node)
end

function GuildWarFightTabPanel:init(data)
    self.super.init(self, data)
    self._guildRender1 = GuildWarFightGuildInfoRender.create(self._ui["Panel/Panel_2/Panel_blue"])
    self._guildRender2 = GuildWarFightGuildInfoRender.create(self._ui["Panel/Panel_2/Panel_red"])
    self._tipPanel = GuildWarFightTipPlateRender.create(self._ui["Panel/Panel_2/Panel_mid"])

    self:registerViewEvent({
        {name = ViewEvent.CSGuildWar_MatchInfo, callback = handler(self, self._onGetMatchInfo)},
       
    })
    self._ui["Panel/Panel_1"]:setVisible(false)
    self._ui["Panel/Panel_2"]:setVisible(false)

    self._ui["Panel/Panel_1/btn_rank"]:addClickEventListener(function()
        UIHandler:handleMessage({id = Constant.FUNC_TYPE_RANK,mode = "open", rankingId = Enums.GuildRankType.CSTotalCombatPower})
    end)
end


function GuildWarFightTabPanel:_onGetMatchInfo()
    self:refreshPanel()
end

function GuildWarFightTabPanel:refreshPanel()
    local csGuildWarData = UD.csGuildWarData
    if csGuildWarData:isMyGuildCanJoin() then
        self._ui["Panel/Panel_1"]:setVisible(false)
        self._ui["Panel/Panel_2"]:setVisible(true)
        local matchInfo = csGuildWarData:getCurMatchInfo()
        if matchInfo then
            local guildData1, guildData2 = matchInfo:getGuildWithSort()
            self._guildRender1:setData(guildData1)
            self._guildRender2:setData(guildData2)
            self._tipPanel:refresh()
        end
    else
        self._ui["Panel/Panel_1"]:setVisible(true)
        self._ui["Panel/Panel_2"]:setVisible(false)
        local tipStr = CrossServerGuildWarHelper.getGuildCanNotJoinDesc()
        self._ui["Panel/Panel_1/text"]:setString(tipStr)
    end

end

function GuildWarFightTabPanel:setPanelTabIndex(index)
    self._tabPanelIndex = index
end


return GuildWarFightTabPanel